/* IF2030 - Algorirma dan Struktur Data */
/* Kelas/Kelompok/Tahun  : 03/09/2011 */
/* Tanggal   : 2 Desember 2011 */
/* File      : mlist.c */
/* Deskripsi : Driver dari ADT List Pengguna dan Pertemanannya */

#include "list.h"

int main() {
    /* Kamus Umum */
    ListPerson Luser;
    ListFriend Lfriend;
    int cmd = -1;
    int n;
    Person X;
    string Xemail,SLahir,PilSort,Sort,Xemail2;
    date XLahir;
    addressPerson P;
    addressFriend F;

    /* Algoritma */
    CreateListPerson(&Luser);
    printf("apakah list user kosong ?? : %d",PersonEmpty(Luser));


    while (cmd != 0) {
        printf("\n---  command avaible :   ");
        printf("\n1. Tambah User");
        printf("\n2. Delete First User (list tidak boleh kosong)");
        printf("\n3. Delete Last User (list tidak boleh kosong)");
        printf("\n4. Delete element pertama menggunakan DelPerson menggunakan address (list tidak boleh kosong)");
        printf("\n5. Print semua user");
        printf("\n6. Jumlah User ");
        printf("\n7. Mengeprint user berdasarkan urutan masukan pilihan ");
        printf("\n8. add friend ");
        printf("\n9. print daftar friend ");
        printf("\n10. print same ");
        printf("\n0. Exit\n> ");

        scanf("%d",&cmd);

        switch (cmd) {
        case 1 : {
            printf(" \n Masukkan alamat Email : ");
            scanf("%s",&(X.DataUser.Email));
            printf(" \n Masukkan Nama user (1 kata) : ");
            scanf("%s",&(X.DataUser.Nama));
            printf(" \n Masukkan tanggal lahir : ");
            scanf("%s",&SLahir);
            X.DataUser.Lahir = StrToDate(SLahir);
            printf(" \n Masukkan Kota asal user : ");
            scanf("%s",&(X.DataUser.Kota));
            printf(" \n Masukkan asal universitas user : ");
            scanf("%s",&(X.DataUser.Universitas));
            printf(" \n Masukkan asal SMA : (1 kata) ");
            scanf("%s",&(X.DataUser.Sma));
            InsertPersonSort(&Luser,X);
            printf(" \n penambahan berhasil ");
            PrintAllPerson(Luser);
            break;
        }
        case 2 : {
            DelFirstPerson(&Luser,&P);
            printf("\n elemen pertama berhasil di delete ");
            break;
        }
        case 3 : {
            DelLastPerson(&Luser,&P);
            printf("\nelemen terakhir berhasil di delete ");
            break;
        }
        case 4 : {
            P = First(Luser);
            DelFirstPerson(&Luser,&P);
            printf("\n elemen pertama berhasil di delete ");
            break;
        }
        case 5 : {
            PrintAllPerson(Luser);
            break;
        }
        case 6 : {
            printf("\n Banyaknya user : %d",NbPerson(Luser));
            break;
        }
        case 7 : {
            printf("sort berdasar [email|name|birthday|hometown|university|highschool]: ");
            scanf("%s",&PilSort);
            printf("urutan sort [asc|desc]: ");
            scanf("%s",&Sort);
            PrintPersonSort(&Luser,PilSort,Sort);
            break;
        }
        case 8 : {
            printf("masukkan email user Anda : ");
            scanf("%s",&Xemail);
            printf("masukkan email user teman Anda : ");
            scanf("%s",&Xemail2);
            InsertFriend(&Friend(EmailSearch(&Luser,Xemail)),EmailSearch(&Luser,Xemail2));
            break;
        }
        case 9 : {
            int j = 1;
            printf("masukkan email user Anda : ");
            scanf("%s",&Xemail);
            while (j<=3) {
                printf("\nteman level: %d\n",j);
                P = First(Luser);
                while (P != Nil) {
                    if (WhichFriend(EmailSearch(&Luser,Xemail),P) == j) {
                        PrintPerson(P);
                    }
                    P = NextPerson(P);
                }
                j++;
            }
            break;
        }
        case 10 : {
            printf("masukkan email user Anda : ");
            scanf("%s",&Xemail);
            printf("same berdasar [school|hometown]: ");
            scanf("%s",&PilSort);
            PrintSamePerson(Luser,EmailSearch(&Luser,Xemail),PilSort);
            break;
        }
        }
    }
    return 0;
}

